<template>
    <div class="search-history">
      <van-cell title="搜索历史" v-show="searchHistories.length">
         <div slot="default" v-if="isDeleteShow">
          <span @click="$emit('remove', -1)">全部删除</span>
          &nbsp;&nbsp;
          <span @click="isDeleteShow=false">完成</span>
         </div>
        <van-icon v-else slot="default" name="delete"
         @click='isDeleteShow = true'/>
      </van-cell>
      <van-cell v-for="(history, index) in searchHistories" :key="index"
        :title="history" @click="onSearchItemClick(history ,index)">
        <van-icon slot="default" v-if="isDeleteShow" name="close"
         />
     </van-cell>
    </div>
  </template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onSearchItemClick (history, index) {
      if (this.isDeleteShow) {
        this.$emit('remove', index)
      } else {
        this.$emit('search', history)
      }
    }
  }
}
</script>

  <style scoped lang="less"></style>
